#include <allegro.h>
#include <time.h>
#include "Mahmoud_bonus2.h" 






int main()
{

BITMAP* t_logo;
BITMAP* r_logo;
BITMAP* c_logo;
BITMAP* t_choix;
BITMAP* r_choix;
BITMAP* c_choix;
BITMAP* tick;
BITMAP* x;
BITMAP* curseur;
BITMAP* buffer;
int j_t=0, j_r=0, j_c=0;



/* General initialization function */
allegro_init();

install_keyboard() ;
if (install_keyboard() == -1) 
{
allegro_message("Error! %s", allegro_error);
return (-1);
}

install_mouse() ;

if (install_mouse () == -1)
{
allegro_message("Erreur ! %s", allegro_error) ;

return -1 ;
}

set_color_depth(32);

if (set_gfx_mode(GFX_AUTODETECT_WINDOWED,800,600,0,0) != 0) 
{
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); /* here’s the command for text mode */
allegro_message("Unable to initialize video mode!\n%s\n", allegro_error);
return (1);
}



load_plaques_l( &t_logo, &r_logo, &c_logo, &t_choix, &r_choix, &c_choix, &tick);
load_cursor(&curseur);
buffer = create_bitmap(SCREEN_W, SCREEN_H) ;
x = load_bitmap("X.bmp", NULL) ;
set_mouse_range(0, 0, SCREEN_W-curseur->w,SCREEN_H-curseur->h);
while(!key[KEY_SPACE] )
{
clear_bitmap(buffer) ;

while(j_t!=1)
{
clear_bitmap(buffer) ;
draw_sprite(buffer, t_logo, 50, 50);	
draw_sprite(buffer, t_choix, 500, 150);
draw_sprite(buffer, curseur, mouse_x, mouse_y);
//draw_sprite(buffer, curseur, 520, 152);
			if (mouse_x < 550 && mouse_x > 500 && mouse_y <225 && mouse_y >200 && (mouse_b & 1))
				{
					draw_sprite(buffer, tick, mouse_x-20, mouse_y);	
					j_t=1;
					blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H) ;
					usleep(500000);
				}
			else if (mouse_b & 1)

				{
					draw_sprite(buffer, x, mouse_x-20, mouse_y);	
				}
blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H) ;
}
clear_bitmap(buffer) ;

while(j_r!=1)
{
clear_bitmap(buffer) ;
draw_sprite(buffer, r_logo, 50, 50);	
draw_sprite(buffer, r_choix, 500, 150);
draw_sprite(buffer, curseur, mouse_x, mouse_y);
//draw_sprite(buffer, curseur, 520, 152);
			if (mouse_x < 550 && mouse_x > 500 && mouse_y <260 && mouse_y >240 && (mouse_b & 1))
				{
					draw_sprite(buffer, tick, mouse_x-20, mouse_y);	
					j_r=1;
					blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H) ;
					usleep(500000);
				}
blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H) ;
}
clear_bitmap(buffer) ;

while(j_c!=1)
{
clear_bitmap(buffer) ;
draw_sprite(buffer, c_logo, 50, 50);	
draw_sprite(buffer, c_choix, 500, 150);
draw_sprite(buffer, curseur, mouse_x, mouse_y);
//draw_sprite(buffer, curseur, 520, 152);
			if (mouse_x < 550 && mouse_x > 500 && mouse_y <175 && mouse_y >150 && (mouse_b & 1))
				{
					draw_sprite(buffer, tick, mouse_x-20, mouse_y);	
					j_c=1;
					blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H) ;
					usleep(500000);
				}
blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H) ;
}
vsync();

blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H) ;
}
destroy_plaques_l (&t_logo, &r_logo, &c_logo, &t_choix, &r_choix, &c_choix, &tick);
destroy_cursor(&curseur);
return 0;
}
END_OF_MAIN();

